﻿using System.Windows;
using System.Diagnostics;
using YAWD.Windows;
using System;
using YAWD.Utils;
using System.Windows.Input;
using System.Windows.Controls;

namespace YAWD
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void mniProvidersConf_Click(object sender, RoutedEventArgs e)
        {

        }

        private void mniPreferences_Click(object sender, RoutedEventArgs e)
        {

        }

        private void mniSkin_Click(object sender, RoutedEventArgs e)
        {

        }

        private void mniLanguage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Cursor = Cursors.Wait;

                MenuItem objClicked = (MenuItem)e.OriginalSource;

                foreach (MenuItem item in ((MenuItem)sender).Items)
                    item.IsChecked = ReferenceEquals(item, objClicked);

                if (objClicked != null)
                    ((App)Application.Current).ApplyLanguage(new Uri(objClicked.CommandParameter as string, UriKind.Relative));

                switch (objClicked.CommandParameter.ToString())
                {
                    case @".\Languages\English.xaml":
                        Util.SaveToConfigFile("DefaultLanguage", "EN");
                        break;
                    case @".\Languages\French.xaml":
                        Util.SaveToConfigFile("DefaultLanguage", "FR");
                        break;
                    case @".\Languages\Russian.xaml":
                        Util.SaveToConfigFile("DefaultLanguage", "RU");
                        break;
                    case @".\Languages\Ukranian.xaml":
                        Util.SaveToConfigFile("DefaultLanguage", "UK");
                        break;
                    default:
                        Util.SaveToConfaigFile("DefaultLanguage", "EN");
                        break;
                }
            }
            catch (Exception ex)
            {
                CatchException(ex);
            }
            finally
            {
                Cursor = null;
            }
        }

        private void mniAbout_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                About objWindow = new About();
                objWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                CatchException(ex);
            }
        }

        private void imgDonate_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Process.Start(@"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=GLKC3RSJTQW2L&lc=FR&item_name=myCollections&item_number=Main&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted");
        }

        private void CatchException(Exception ex)
        {
            Util.LogException(ex);
            MessageBox.Show(this, ex.Message);
        }
    }
}
